package com.chao.mail.core.impl

import com.chao.mail.core.Mail
import com.chao.mail.core.interfaces.IMailRepository
import com.chao.mail.repositories.dao.MailDao
import com.chao.mail.repositories.entity.MailPo
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

@Service
class MongoMailRepository: IMailRepository {
    @Autowired
    lateinit var mailDao: MailDao

    override fun insertMail(mail: Mail) {
        val mailPo = MailPo(
                from = mail.from,
                to = mail.to,
                subject = mail.subject,
                text = mail.text,
                cc = mail.cc,
                bcc = mail.bcc,
                sendData = mail.sentDate
        )
        mailDao.save(mailPo)
        mail.id = mailPo.id
    }
}